<!DOCTYPE html>
<html lang="en">

<include file="CommonSidebar:common-head"/>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/css/common.css">
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">套装书《{$ListData['NAME']}》中的书籍</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="col-md-12">
                    <if condition="$count gt 0">
                        <span class="btn  btn-primary">还差（{$count}）本书</span>
                        <a href="{:U('Book/Index')}?TZ={$ListData['ID']}" target="_blank"
                           class="btn  btn-primary">从主库中完导入书籍</a>
                        <a onclick='AddTZBookShow("{$ListData.ID}")' target="_blank" class="btn  btn-primary">手动添加</a>
                    <else/>
                        <span style="color: red" class="btn  btn-primary">已完善</span>
                    </if>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center"><input name="all_checkbox" type='checkbox'
                                                                             id="all_checkbox"></th>
                                        <th style="text-align:center">条形码</th>
                                        <th style="text-align:center" width="20%">书名</th>
                                        <th style="text-align:center" width="8%">作者</th>
                                        <th style="text-align:center">出版社</th>
                                        <th style="text-align:center">书籍包装</th>
                                        <th style="text-align:center">库存</th>
                                        <th style="text-align:center" width="15%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="DATA" item="v" key="k">
                                        <tr class="odd gradeX">
                                            <if condition="$v['BOOK_ID']">
                                                <td></td>
                                                <else/>
                                                <td><input type='checkbox' name="checkbox" value="{$v.ID}"></td>
                                            </if>
                                            <td>{$v.ISBN}</td>
                                            <td>{$v.TITLE}</td>
                                            <td>{$v.AUTHOR}</td>
                                            <td>{$v.PRESS}</td>
                                            <td>{$v.PACKING_SPECIFICATION}</td>
                                            <td>{$v.STOCK}</td>
                                            <td class="center" style="text-align:center">
                                                <if condition="$v.STOCK gt 0">
                                                    <a href="javascript:void(0)"
                                                       onclick="ckwz('{$v.ID}',$(this))"
                                                       class="btn btn-warning btn-xs" title="Delete">查看位置</a>
                                                </if>
                                                <a href="{:U('Book/EditBookIndex')}?ID={$v.ID}"
                                                   class="btn btn-warning btn-xs"
                                                   target="_blank">查看书籍</a>
                                                <a onclick='Del("{$v.tz_book_id}",$(this));'
                                                   class="btn btn-warning btn-xs"
                                                   title="Edit">移除</a>
                                            </td>
                                        </tr>
                                    </foreach>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>

                    </div>
                </div>


            </div>
        </div>

    </div>
</div>
<!--添加套装书籍-->
<div id="ADDTZBOOK" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">添加套装书籍</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <input id="TZ_ID" type="hidden" name="TZ_ID" value="">

                        <div class="col-xs-12">
                            <label>书名</label>
                            <input class="rugby-login form-control" id="TITLE" name="TITLE">
                        </div>
                        <div class="col-xs-12">
                            <label>丛书名</label>
                            <input class="rugby-login form-control" id="TITLE_C" name="TITLE_C">
                        </div>
                        <div class="col-xs-12">
                            <label>ISBN</label>
                            <input class="rugby-login form-control" id="ISBN" name="ISBN">
                        </div>
                        <div class="col-xs-12">
                            <label>定价</label>
                            <input class="rugby-login form-control" id="Y_PRICE" name="Y_PRICE">
                        </div>
                        <div class="col-xs-12">
                            <label>作者</label>
                            <input class="rugby-login form-control" id="AUTHOR" name="AUTHOR">
                        </div>
                        <div class="col-xs-12">
                            <label>出版社</label>
                            <input class="rugby-login form-control" id="PRESS" name="PRESS">
                        </div>
                        <div class="col-xs-12">
                            <label>包装规格</label>
                            <select class="rugby-login form-control" id="PACKING_SPECIFICATION"
                                    name="PACKING_SPECIFICATION">
                                <foreach name="BOOK_BZ" item="v" key="k">
                                    <option value="{$v.region_name}">{$v.region_name}</option>
                                </foreach>
                            </select>
                        </div>
                        <div class="col-xs-6 modal-footer">
                            <button onclick="AddBook()" class="btn btn-block btn-primary">保存</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<!--添加套装书籍-->

<!--查看位置-->
<div id="WZModal" class="modal fade bs-example-modal-sm" data-backdrop='static' tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true" style="font-size:35px">&times;</span></button>
                <h3 class="modal-title text-center">成套书籍位置单</h3>
            </div>
            <div class="modal-body" style="padding-top:0px;padding-bottom:5px;">
                <div class="row" style="height:530px;overflow-y:scroll;">
                    <div class=" spell-list"
                         style="height:100%; background:#f0f0f0; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="panel-body">
                                    <div class="dataTable_wrapper">
                                        <table class="table table-striped table-bordered table-hover"
                                               id="dataTables-example1">
                                            <thead>
                                            <tr>
                                                <th style="text-align: center">书名</th>
                                                <th style="text-align: center">仓库</th>
                                                <th style="text-align:center">书架</th>
                                                <th style="text-align:center">书柜</th>
                                            </tr>
                                            </thead>
                                            <tbody id="WZDATA">

                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- /.table-responsive -->
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--查看位置-->

<include file="CommonSidebar:common-script"/>
<script src="__ROOT__/Application/Admin/Public/js/jquery.datetimepicker.js"></script>
<!-- DataTables JavaScript -->
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->


<script type="text/javascript" src="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.js?v=3"></script>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.css" type="text/css"
      media="screen"/>


<script>

    //  移除书籍
    function Del(ID, elem) {
        if (confirm("确认移除？")) {
            $.post("{:U('Book/DelTZBOOK')}",
                    {ID: ID},
                    function (data) {
                        if (data == 1) {
                            alert('移除成功');
                            elem.parent().parent().remove();
                        } else {
                            alert('移除失败');
                        }
                    });
        }

    }


    $(document).ready(function () {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
</script>
<script>
    <!--全选择框-->
    $("#all_checkbox").click(function () {
        if ($(this).is(':checked')) {
            $("input[name='checkbox']").prop("checked", "true");
        } else {
            $("input[name='checkbox']").removeAttr("checked", false);

        }
    })
    function checkboxID() {
        var vals = [];
        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
            vals.push($(this).val());
        });
        if (vals.length <= 0) {
            alert('请选择书籍');
            return 0;
        }
        $.post("{:U('Basket/AddAll')}",
                {IDS: vals},
                function (data) {
                    console.log(data);
                    if (parseInt(data)) {
                        alert('导入书篮子成功');
                        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
                            $(this).hide();
                        });
                    } else {
                        alert('导入书篮子失败');
                        window.location.reload()
                    }

                });
    }

    //添加书籍显示弹窗
    function AddTZBookShow(TZ_ID) {
        $('#TZ_ID').val(TZ_ID);
        $('#ADDTZBOOK').modal('show');
    }
    //添加书籍操作
    function AddBook() {
        var TZ_ID = $('#TZ_ID').val();
        var TITLE = $('#TITLE').val();
        var TITLE_C = $('#TITLE_C').val();
        var ISBN = $('#ISBN').val();
        var AUTHOR = $('#AUTHOR').val();
        var PRESS = $('#PRESS').val();
        var PACKING_SPECIFICATION = $('#PACKING_SPECIFICATION').val();
        var Y_PRICE = $('#Y_PRICE').val();
        $.post("{:U('Book/TZ_AddBook')}",
                {
                    TZ_ID: TZ_ID,
                    TITLE: TITLE,
                    TITLE_C: TITLE_C,
                    ISBN: ISBN,
                    AUTHOR: AUTHOR,
                    PRESS: PRESS,
                    PACKING_SPECIFICATION: PACKING_SPECIFICATION,
                    Y_PRICE: Y_PRICE
                },
                function (data) {
                    console.log(data);
                    if (parseInt(data) > 0) {
                        if (confirm("添加成功，是否前往完善书籍信息？")) {
                            window.location.href = "{:U('Book/EditBookIndex')}?ID=" + data;
                        } else {
                            window.location.reload()
                        }
                    } else {
                        alert('添加失败');
                        window.location.reload()
                    }

                });
    }


    //    查看书籍位置
    function ckwz(ID) {
        $.post("{:U('GetTZBookWZ')}",
                {ID: ID},
                function (data) {
                    console.log(data);
                    var html = '';
                    $("#WZDATA").html("");
                    for (var i = 0; i < data.length; i++) {
                        console.log(data[i]);
                        html += "<tr class='odd gradeX'> ";
                        html +=
                                "<td class='enter' style='text-align:center'> " +
                                data[i]['TITLE'] +
                                "</td> " +
                                "<td class='enter' style='text-align:center'> "
                                + data[i]['c_P']
                                + data[i]['c_C']
                                + data[i]['c_Z']
                                + data[i]['c_ADDRESS']
                                + data[i]['c_NAME'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'> "
                                + data[i]['j_CODE'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'> "
                                + data[i]['g_CODE'] +
                                "</td> ";
                        html += "</tr>";
                    }
                    $("#WZDATA").append(html);

                    $("#WZModal").modal("show");
                });
    }

</script>
</body>

</html>
